#ifndef DIAMOND_H
#define DIAMOND_H

#include "MoveableObj.h"

#define A_MOVE 1000
#define A_DROP 600
#define V_LIMIT 400

#define W_SPRITE_EFFECT 40
#define H_SPRITE_EFFECT 40
#define SCALE_EFFECT 1.25

//Vibrate
#define REDUCE_AMPLITUDE 1	//amplitude will decrease in a frame.
#define ANGLE_FOR_AMPLITUDE_INCREASE 1
#define VIBRATE_AMTITUDE_1 7
#define VIBRATE_AMTITUDE_2 5
#define VIBRATE_AMTITUDE_3 2

enum DIAMOND_STATE
{
	DMS_IDLE,
	DMS_DROPDOWN_AUTO,
	DMS_MOVE,
	DMS_DIE,
};

enum DIAMOND_EFFECT{
	DME_NORMAL,
	DME_EAT4,
	DME_EAT5,
	DME_EAT5X5,
};

enum DIAMOND_DIRECTION
{
	DMD_LEFT,
	DMD_RIGHT,
	DMD_TOP,
	DMD_BOTTOM,
};

enum DM_ANI_ID
{
	DM_ANI_DIAMOND,
	DM_ANI_EXPLODING,
	DM_ANI_EFFECT_EAT4,
	DM_ANI_EFFECT_EAT5,
	DM_ANI_EFFECT_EAT5X5,
};

class Vector;
class Board;
class Cell;
class AnimationSprite;

class Diamond:public MoveableObj
{
private:
	int id;
	Cell* cell;
	Board* board;
	float angleForAnimation;
	Vector* nextPos;
	Vector* oldPos;
	bool isActive;
	bool isExploding;

	void CheckStopWhenDrop();
	
	//variable for calculate moving
	bool isReturn;
	int directionMove;
	float length;
	int lengthNeedMove;

	float dxVibrate;					//delta x add by origin x to make vibrate effect
	bool isVibrate;
	float amplitude;					//amplitude of vibrate.
	float angleToCalculateDxVibrate;	//angle, mutiply with sin its to calculate dxVibrate.
	bool isEnableVibrate;
	int effect;							//set when player eat 4, 5 diamond...
public:
	bool isTouchDown;
	float angle;
	int oldState;
	bool isAddedToAteList;

	Diamond();
	Diamond(int id, Board* board);
	void Update();
	void Render();
	void SetState(int state);
	void Move(int direction, bool isReturn);
	void SetID(int id);
	void ResetPositionToItsCell();
	void Vibrate(float amplitude);

	// when diamond drop down, it will check if next cell has
	// diamond, it will stop. But when speed too fast, it will
	// may be move to cell, which had diamond. So, this function
	// will move diamond return empty cell, use recursive
	void StopDiamondWhenNextCellNotEmpty(int xBoard, int yBoard);
	virtual ~Diamond();

	void SetCell(Cell* cell);
	void SetIsActive(bool isActive);
	void SetIsExploding(bool isExploding);
	void SetIsEnableVibrate(bool isEnableVibrate);
	void SetEffect(int effect);

	int GetID(){return id;}
	Cell* GetCell(){return cell;}
	bool GetIsActive(){return isActive;}
	bool GetIsExploding(){return isExploding;}
	bool GetIsVibrate(){return isVibrate;}
	bool GetIsEnableVibrate(){return isEnableVibrate;}
	int GetEffect(){return effect;}

	static int GetRevertDir(int direction);
};

#endif